package com.example.demo.mapper;

import com.example.demo.model.VipOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VipOrderMapper {
    @Insert("INSERT INTO `vip_order` (user_id, product_id, price, status, created_at, updated_at) VALUES (#{userId}, #{productId}, #{price}, #{status}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertOrder(VipOrder order);

    @Update("UPDATE `vip_order` SET status = #{status}, updated_at = CURRENT_TIMESTAMP WHERE id = #{id}")
    void updateStatus(@Param("id") Long id, @Param("status") String status);

    @Select("SELECT * FROM `vip_order` WHERE user_id = #{userId} ORDER BY created_at DESC")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "productId", column = "product_id"),
            @Result(property = "price", column = "price"),
            @Result(property = "status", column = "status"),
            @Result(property = "createdAt", column = "created_at"),
            @Result(property = "updatedAt", column = "updated_at")
    })
    List<VipOrder> findByUserId(@Param("userId") Long userId);
}